<template>
	<view class="login">
		<image :src="userinfo.avatarUrl" mode=""></image>
		<button class="wxq-btn loginWx" @tap="shouquan">一键登录</button>
		<button class="wxq-btn goback" @tap="handle">取消登录</button>
		{{address}}
	</view>

</template>

<script>
	import { mapState } from "vuex"
	export default {

		data() {
			return {
			
			}
		},
		mounted() {
			let userinfo1 = uni.getStorageSync('userinfo')
			console.log(userinfo1)
			
			wx.cloud.callFunction({
			  name:'openid',
			  data:{
			    message:'helloCloud',
			  }
			}).then(res=>{
			  console.log(res.result.openid,1234567)
			}).catch((err) => {
				console.log('失败')
			})
			
		},
		methods: {
			shouquan() {
				console.log(123)
				uni.getUserProfile({
					desc: '登录',
					success: (res) => {
						if (res.errMsg == 'getUserProfile:ok') {
							uni.showToast({
								title: '登入成功!',
								duration: 2000 //持续时间为 2秒
							})
							console.log(res)
							uni.setStorageSync('userinfo',JSON.stringify(res.userInfo))
							console.log(this.getToken())
						}
					},
					fail: (res) => {
						uni.showToast({
						    title: '登入失败',
							icon: 'error',
						    duration: 2000
						});
					}
				});
			},
			
			async getToken(userinfo){
				console.log(1234567)
				const [err,res] = await uni.login()
				if(res.errMsg != 'login:ok'){
					uni.showToast({
					    title: '登入失败',
						icon: 'error',
					    duration: 2000
					});
				}
				
				
			
			},
			handle(){
				const pages = getCurrentPages()
				pages.onLoad
			}
			
			
		},
	
		computed: {
			...mapState(['userinfo','address']),
		}

	}
</script>

<style>

</style>
